package org.nowcoder.huawei.c200;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**
 * 32:连续出牌数量
 */
public class HC032 {
    static class Card {
        private int num;
        private String color;

        public Card(int num, String color) {
            this.num = num;
            this.color = color;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Card card = (Card) o;
            return num == card.num && Objects.equals(color, card.color);
        }

        @Override
        public int hashCode() {
            return Objects.hash(num, color);
        }
    }

    private static LinkedList<Card> path = new LinkedList<>();

    private static int max = Integer.MIN_VALUE;

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String[] nums = br.readLine().split(" ");
            String[] colors = br.readLine().split(" ");
            Card[] cards = new Card[nums.length];
            for (int i = 0; i < nums.length; i++) {
                cards[i] = new Card(Integer.parseInt(nums[i]), colors[i]);
            }
            solve(cards);
            System.out.println(max);
        } catch (Exception ignore) {

        }
    }


    public static void solve(Card[] cards) {
        if (path.size() == cards.length) {
            max = Math.max(max(path), max);
            return;
        }
        for (int i = 0; i < cards.length; i++) {
            if (path.contains(cards[i])) continue;
            path.add(cards[i]);
            solve(cards);
            path.removeLast();
        }
    }

    public static int max(List<Card> cards) {
        int max = 1;
        Card pre = cards.get(0);
        for (int i = 1; i < cards.size(); i++) {
            Card cur = cards.get(i);
            if (pre.color.equals(cur.color) || pre.num == cur.num) {
                max++;
                pre = cur;
            } else {
                break;
            }
        }
        return max;
    }
}
